*** Settings ***
Documentation    TC03-Data Cleaning LCL Project By Port
Resource    ../../Keywords/Common_Head.robot
Force Tags    P1
Metadata    Author    Joe
Metadata    ID    6850937


*** Test Cases ***
TC03-Data Cleaning LCL Project By Port
    Step 1 User Goes To Basic Data Management Tender List
    Step 2 User Goes To Pricing Collaboration Pricing Project
    Step 3 Input Following Attributes
    Step 4 User Select The Row Which Project Name Is 20240815 LCL
    Step 5 User Clicks Data Cleaning Button
    Step 6 User Clicks Upload Button
    Step 7 User Clicks Add File Button And Select The File
    Step 8 User Select Port Routing
    Step 9 User Clicks Start Button
    Step 10 User Clicks Download Button
    Step 11 Check The Values Of Download File With The Original
    Step 12 Modify The Download File And User Clicks Upload Button
    Step 13 User Click Start Button
    Step 14 User Click Download Button
    Step 15 User Clicks Close Button
    Step 16 User Clicks Yes When Asking Are You Sure To Close This
    Step 17 In Pricing Project Page User Selects TenderID Contains
    Step 18 Select This Project Click On Delete Project Button
    Step 19 User Goes To Basic Data Management Tender List2



*** Keywords ***
Step ${step} User Goes To Basic Data Management Tender List
    #************************Step 1******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Click Create button
    #      Input with following attributes
    #      Tender ID some numbers such as 202408151435001 you can
    #     input with current datetime and some random number to
    #     avoid duplicate validation
    #      Tender Title some value such as Regression Test by
    #     Wendy001
    #      Customer 815 Miele
    #      Mode select all
    #      Level Global
    #      Click on Save button
    #  Expected:
    #      Created successfully with the message Tender has been
    #     added
    #************************************************************
    ${G_TENDERID}    Generate Tender ID
    Set Suite Variable     ${G_TENDERID}
    Login Space
    Create Tender    ${G_TENDERID}    Regress    815    true    true    true

Step ${step} User Goes To Pricing Collaboration Pricing Project
    #************************Step 2******************************
    #  Do:
    #      User goes to Pricing Collaboration Pricing Project
    #      User clicks Create Project button
    #  Expected:
    #      A New Project dialog should be opened successfully
    #************************************************************
    ${ValidFrom}    Get Current Date    result_format=%d/%m/%Y
    Set Test Variable    ${ValidFrom}    ${ValidFrom}

Step ${step} Input Following Attributes
    #************************Step 3******************************
    #  Do:
    #      Input following attributes
    #      Tender ID 20240815 Regression
    #      Mode Air
    #      Deadline to TM current date 10 day
    #      Rate Validity From current date
    #      Rate Validity To current date 100 day
    #      Deputies NATZHANG
    #      Description for regression
    #      Click on Save button
    #  Expected:
    #      A new project is created successfully
    #************************************************************
    ${CurDate}    Get Current Date    result_format=%d/%m/%Y
    Set Test Variable    ${CurDate}    ${CurDate}
    ${DeadLine}    Get Current Date    UTC    +10days    result_format=%d/%m/%Y
    ${ValidTo}    Get Current Date    UTC    +100days    result_format=%d/%m/%Y
    ${PROJECT}    Copy Dictionary    ${PROJECT_PARAM}
    Set To Dictionary    ${PROJECT}    
    ...    TENDER_ID=${G_TENDERID}    TENDER_TITLE=Regress    CUSTOEMR_NAME=Miele    CUSTOMER_LEVEL=Global
    ...   MODE=LCL    DEADLINE_TM_DATE=${DeadLine}    VALID_FROM=${ValidFrom}    VALID_TO=${ValidTo}    DEPUTY=NATZHANG
    Set Test Variable    ${PROJECT}    ${PROJECT}
    Create Project    ${PROJECT}


Step ${step} User Select The Row Which Project Name Is 20240815 LCL
    #************************Step 4******************************
    #  Do:
    #      User select the row which project name is 20240815 LCL
    #     Regression
    #  Expected:
    #      The row is selected and the button of data cleaning is
    #     enabled
    #************************************************************
    Search Project    ${PROJECT.TENDER_ID} 
    Wait For Elements State    ${Project_toolbar_DataCleaningButton}    enabled    20

Step ${step} User Clicks Data Cleaning Button
    #************************Step 5******************************
    #  Do:
    #      User clicks data cleaning button
    #  Expected:
    #      A dialogue named 20240815 LCL Regress shows
    #     successfully
    #************************************************************
    click    ${Project_toolbar_DataCleaningButton}
    Wait For Elements State    //h4[contains(text(),'${G_TENDERID}')]    visible    20

Step ${step} User Clicks Upload Button
    #************************Step 6******************************
    #  Do:
    #      User clicks upload button
    #  Expected:
    #      A dialogue name Upload Template shows successfully
    #************************************************************
    Click    ${Data_toolbar_UploadButton}
    Wait For Elements State    ${Data_Upload_AddFile}    enabled    60

Step ${step} User Clicks Add File Button And Select The File
    #************************Step 7******************************
    #  Do:
    #      User clicks add file button and select the file
    #     LCLTemplate Port All xlsx form local
    #  Expected:
    #      A table shows below upload button It contains document
    #     name and date time Document name is LCLTemplate Location
    #     All xlsx date time is you uploaded time like 03 10 2018
    #     17 05
    #************************************************************
    ${Data_Upload_AddFile1}    Set Variable    xpath=//input[@name='file']
    Upload File By Selector    ${Data_Upload_AddFile1}    ${CURDIR}${/}TestData${/}TC-03LCLTemplate-Port-all.xlsx
    Wait For Elements State    xpath=//label[.='Document Name']    visible    30 
    Wait For Elements State    //label[.='TC-03LCLTemplate-Port-all.xlsx']    visible    20
    Wait For Elements State    //label[contains(text(),'${CurDate}')]    visible    20 

Step ${step} User Select Port Routing
    #************************Step 8******************************
    #  Do:
    #      User select port routing
    #      Select all of them
    #      User select map columns like that
    #      Origin Country country from D
    #      Destination Country country to G
    #      Origin Port origin prot N
    #      Destination Port destination port O
    #      Origin State state from E
    #      Destination State state to H
    #      Origin Type origin type l
    #      Destination Type des type J
    #      Origin Postal Code Origin Postal Code K
    #      Destination Postal Code Destination Postal Code L
    #      Customer Lane ID Lane ID code B
    #      Customer s Delivery Term Customer s Delivery Term M
    #      Place Origin place origin G
    #      Place Destination place des H
    #      Number of Shipments number of shipments P
    #      Weight in Metric Tons weight in metric tons Q
    #      Volume in cbm volume in cbm R
    #      Commodity Description commodity description S
    #      IMO Class IMO Class T
    #      IMO UN No IMO UN No U
    #  Expected:
    #      They both should be select successfully
    #************************************************************
    click    ${Select_By_Port}
    Select Options By   ${Origin_Country}    label      ${space}${space}country from - C
    Select Options By   ${Destination_Country}     label    ${SPACE}${SPACE}country to - E
    Select Options By   ${Origin_Port}    label    origin port - N
    Select Options By   ${Destination_Port}    label    destination port - O
    Select Options By   ${Origin_State}      label      State From - D
    Select Options By   ${FCL_Select_Destination_State}   label    place des - H
    Select Options By   ${Origin_Type}    label     origin type - I
    Select Options By   ${Destination_Type}    label    des type - J
    Select Options By   ${Origin_Postal_Code}     label    Origin Postal Code - K
    Select Options By   ${Destination_Postal_Code}  label    Destination Postal Code - L
    Select Options By   ${LCL_Customer_Lane_ID}   label       Lane ID code - B
    Select Options By   ${LCL_Customer_Deliver_Term}   label      Customer's\nDelivery\nTerm - M
    Select Options By   ${LCL_Place_Origin}     label    place origin - G
    Select Options By   ${LCL_Place_Dest}   label    place des - H
    Select Options By   ${LCL_Number_of_Shipments}    label    number of shipments - P
    Select Options By   ${LCL_Weight_in_Metric_Tons}      label    weight in Metrics tons - Q
    Select Options By   ${LCL_Volume_in_cbm}  label    volumn in cbm - R
    Select Options By   ${LCL_Commodity_Desc}     label    commodity description - S
    Select Options By   ${LCL_IMO_Class}   label    IMO Class - T
    Select Options By   ${LCL_IMO_UN_No}   label    IMO UN No. - U
    click    ${AIR_CheckBox__OriginState} 
    click    ${AIR_CheckBox__DestinationState}
    click    ${FCL/AIR_CheckBox_OriginType}
    click    ${FCL/AIR_CheckBox_DestType}
    click    ${FCL/AIR_CheckBox_OriginPostalCode}
    click    ${FCL/AIR_CheckBox_DestiPostalCode} 
    click    ${FCL/AIR_CheckBox_CustomerLaneID}
    click    ${FCL_CheckBox_CustomerDelTerm}
    click    ${FCL/AIR_CheckBox_Place Origin}
    click    ${FCL/AIR_CheckBox_Place Destination}
    click    ${AIR_CheckBox_NoOfShipments}
    click    ${AIR_CheckBox_Volume in cbm} 
    click    ${AIR_CheckBox_Weight in Metric Tons}
    click    ${FCL/AIR_CheckBox_CommDesc} 
    click    ${FCL_CheckBox_IMOClass}
    click    ${FCL_CheckBox_IMOUNNo}


Step ${step} User Clicks Start Button
    #************************Step 9******************************
    #  Do:
    #      User clicks start button
    #  Expected:
    #      In the tab of step3 validation download upload and set
    #     pass buttons appears The summary shows successful
    #************************************************************
    click    ${Data_toolbar_StartButton}
    Wait For Elements State    ${Data_toolbar_DownloadButton}    visible    30 
    Wait For Elements State   ${Data_toolbar_UploadAfterStartButton}    visible    30 
    Wait For Elements State    ${Data_toolbar_SetPassButton}     visible    30 
    ${content}    Get Text    //div[@class="row form-group col-md-12 ng-scope"][2]
    Should Contain    ${content}    Summary: Successful
    Should Contain    ${content}    Please close this page and go to Generate Internal Pricing Template.

Step ${step} User Clicks Download Button
    #************************Step 10******************************
    #  Do:
    #      User clicks download button
    #  Expected:
    #      File download successfully and the file named
    #     LCL_data_cleaning_template xlsx
    #************************************************************
    ${file_path}    Get Download ZIP File Name    ${G_TENDERID}    .zip
    ${DOWNLOAD_PATH}     Normalize Path    ${DOWNLOAD_PATH}
    Extract Zip File    ${file_path}    ${DOWNLOAD_PATH}
    ${FILES}    List Files In Directory   ${DOWNLOAD_PATH}   *.xlsx
    ${excelFile}     Set Variable    ${DOWNLOAD_PATH}${/}${FILES}[0]
    Set Test Variable    ${excelFile}    ${excelFile}
    

Step ${step} Check The Values Of Download File With The Original
    #************************Step 11******************************
    #  Do:
    #      Check the values of download file with the original
    #     file LCLTemplate Port All xlsx
    #  Expected:
    #      Compare the two files the value of the same column
    #     which selected in step 8 should be equal except state
    #************************************************************
    Wait Until Keyword Succeeds    50    1    Open Excel Document    ${excelFile}    LCL
     ${Origin Country}    Read Excel Cell    2    7
     ${Destination Country}    Read Excel Cell    3    14
     ${Origin Airport}    Read Excel Cell    2    19
     ${Origin type}    Read Excel Cell    2    18
     ${Destination type}    Read Excel Cell    3    23
     ${Origin Postal Code}    Read Excel Cell    3    10
     ${Destination Postal Code}    Read Excel Cell    3    17
     ${Origin City}    Read Excel Cell    2    8
     ${Destination City}    Read Excel Cell    2    15
     ${Number of Shipments}    Read Excel Cell    2    26
     ${Volume(cbm)}    Read Excel Cell    2    28
     ${Actual weight in kg}    Read Excel Cell    2    27
     ${Chargeable weight in kg}    Read Excel Cell    2    29
     ${Commodity Description}    Read Excel Cell    2    30
     ${Commodity Remarks}    Read Excel Cell    2    31
     Close All Excel Documents
     Open Excel Document    ${CURDIR}${/}TestData${/}TC-03LCLTemplate-Port-all.xlsx    LCL
     ${Country from}    Read Excel Cell    2    3
     ${Country to}    Read Excel Cell    3    5
     ${Customer origin airport}    Read Excel Cell    2    14
     ${Origin type2}    Read Excel Cell    2    9
     ${Destination type2}    Read Excel Cell    3    10
     ${Origin Postal Code2}    Read Excel Cell    3    11
     ${Destination Postal Code2}    Read Excel Cell    3    12
     ${city from}    Read Excel Cell    2    7
     ${city to}    Read Excel Cell    2    8
     ${Number of Shippments2}    Read Excel Cell    2    16
     ${Volume (cbm)2}    Read Excel Cell    2    18
     ${Actual weight in kg2}    Read Excel Cell    2    17
     ${Chargeable weight in kg2}    Read Excel Cell    2    19
     ${Commodity Description2}    Read Excel Cell    2    20
     ${Commodity Remarks2}    Read Excel Cell    2    21
    Close All Excel Documents
    Should Be Equal    ${Origin Country}    ${Country from}
    Should Be Equal    ${Destination Country}     ${Country to}
    Should Be Equal    ${Origin Airport}    ${Customer origin airport}
    Should Be Equal    ${Origin type}     ${Origin type2}
    Should Be Equal    ${Destination type}     ${Destination type2} 
    Should Be Equal    ${Origin Postal Code}     ${Origin Postal Code2}
    Should Be Equal    ${Destination Postal Code}    ${Destination Postal Code2}
    Should Be Equal    ${Origin City}     ${city from}
    Should Be Equal    ${Destination City}     ${city to}
    Should Be Equal    ${Number of Shipments}     ${Number of Shippments2}
    Should Be Equal    ${Volume(cbm)}     ${Volume (cbm)2}
    Should Be Equal    ${Actual weight in kg}     ${Actual weight in kg2}
    Should Be Equal    ${Chargeable weight in kg}    ${Chargeable weight in kg2}
    Should Be Equal    ${Commodity Description}     ${Commodity Description2}
    Should Be Equal    ${Commodity Remarks}     ${Commodity Remarks2}

Step ${step} Modify The Download File And User Clicks Upload Button
    #************************Step 12******************************
    #  Do:
    #      Modify the download file and user clicks upload button
    #  Expected:
    #      The start button appears
    #************************************************************
    Open Excel Document    ${excelFile}    LCL
    Write Excel Cell    2    26    12    LCL
    Save Excel Document   ${excelFile}
    Close All Excel Documents
    Data Upload Template After Modified    ${G_TENDERID}-LCL-Regress   ${excelFile}
    Wait For Elements State   ${Data_toolbar_StartButton}     enabled

Step ${step} User Click Start Button
    #************************Step 13******************************
    #  Do:
    #      User click start button
    #  Expected:
    #      Wait a few seconds there is a successful prompt below
    #     the buttons like that Summary Successful
    #      Please close this page and go to Generate Internal
    #     Pricing Template
    #************************************************************
    Click    ${Data_toolbar_StartButton}
    Remove All Files

Step ${step} User Click Download Button
    #************************Step 14******************************
    #  Do:
    #      User click download button
    #  Expected:
    #      File download successfully Check the modified area the
    #     values are equal with the modified values
    #************************************************************
    ${zipFile}    Get Download ZIP File Name    ${G_TENDERID}    .zip
    Check Modified Excel File    ${zipFile}    2    26    LCL    12

Step ${step} User Clicks Close Button
    #************************Step 15******************************
    #  Do:
    #      User clicks close button
    #  Expected:
    #      A warning dialogue display and ask you Are you sure to
    #     close this page
    #************************************************************
    click    ${Data_toolbar_CloseButton} 

Step ${step} User Clicks Yes When Asking Are You Sure To Close This
    #************************Step 16******************************
    #  Do:
    #      User clicks yes when asking Are you sure to close this
    #     page
    #  Expected:
    #      The dialogue disappears
    #************************************************************
    click    //button//span[.='Yes']

Step ${step} In Pricing Project Page User Selects TenderID Contains
    #************************Step 17******************************
    #  Do:
    #      In Pricing Project page User selects TenderID Contains
    #     20240815
    #  Expected:
    #      The project 20240815 LCL Regression could be found
    #************************************************************
    click    //td[contains(text(),'${G_TENDERID}')]

Step ${step} Select This Project Click On Delete Project Button
    #************************Step 18******************************
    #  Do:
    #      Select this project click on Delete Project button
    #      Click Yes of the pop up confirm window
    #  Expected:
    #      System displays Project has been deleted
    #************************************************************
    LOG    TEARDOWN

Step ${step} User Goes To Basic Data Management Tender List2
    #************************Step 19******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Search out the tender created in step1
    #      Click on Delete button
    #      Click on Yes button in the popup dialog
    #  Expected:
    #      System displays Tender has been deleted
    #************************************************************
    LOG    TEARDOWN

